package com.woniu.service.imp;

import com.woniu.dao.HomeMapper;
import com.woniu.dto.HomeDetail;
import com.woniu.pojo.Home;
import com.woniu.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HomeServiceImp implements HomeService {

    @Autowired
    HomeMapper homeMapper;

    @Override
    public HomeDetail getHome(long id)
    {
        return homeMapper.getHomeByUserId(id);
    }

    @Override
    public String updateHome(String address,Long id)
    {
        int i = homeMapper.updateByKey(address,id);
        if (i != 0)
        {
            return "修改成功";
        } else
        {
            return "修改失败";
        }
    }

    @Override
    public String addHome(Home home)
    {
        int insert = homeMapper.insert(home);
        if (insert!=0){
            return "新增成功";
        }else {
            return "新增失败";
        }
    }

    @Override
    public String deleteHome(Long id)
    {
        int i = homeMapper.deleteByPrimaryKey(id);
        if (i!=0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }
}
